﻿using NLog;
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;

namespace GuiZhou.ImageArchive.Update
{
    static class Program
    {

        public static Logger logger = LogManager.GetCurrentClassLogger();
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            string strProcessName = Process.GetCurrentProcess().ProcessName;
            if (Process.GetProcessesByName(strProcessName).Length <= 1)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }

            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            Application.ThreadException += Application_ThreadException;

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
        }

        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;
            logger.Error("子线程发生异常：" + ex.Message + Environment.NewLine + ex.StackTrace);
        }

        private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            logger.Error("主线程异常："  + e.Exception.Message + Environment.NewLine + e.Exception.StackTrace);
        }

        private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
        {
            logger.Info("程序退出");
        }
    }
}
